package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

/**
 * 表单自动布局的列
 * @author rebin
 *
 */
public class FormCell extends NokaTag{
	private static final long serialVersionUID = -5547114817606218848L;
	private String style="float:left;";//style
	private String classstyle=""; //classstyle
	private String inputStyle=null;
	private String inputclassstyle=null;
	private String label=null; //classstyle
	private String labelwidth = null;
	private String labelheight = null;
	private String inputwidth = null;
	private String inputheight = null;
	private String labelid = null;
	private String inputid = null;
	
	public int doStartTag() throws JspException {
		JspWriter jspOut = pageContext.getOut();
		StringBuilder bodystr = new StringBuilder();
		if(label!=null)
			bodystr.append("<div "+(labelid==null?"":"id=\""+labelid+"\"")+" style=\""+style+getLabelDefaultwidthHeight()+"\" class=\""+classstyle+"  nkform_label\">"+label+"</div>");
		bodystr.append("<div "+(inputid==null?"":"id=\""+inputid+"\"")+"  style=\""+(inputStyle==null?style:inputStyle)+getInputDefaultwidthHeight()+"\" class=\""+(inputclassstyle==null?classstyle:inputclassstyle)+"  nkform_input\">");
		try {
			jspOut.write(bodystr.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}
	public int doEndTag() throws JspException {
		try {
			StringBuilder bodystr = new StringBuilder();
			bodystr.append("</div>");
			pageContext.getOut().write(bodystr.toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		return EVAL_PAGE;
	}
	//--------获取默认宽/高度---------------------------------
	public String getLabelDefaultwidthHeight(){
		String rts = "";
		FormRow formRow = null;//
		try{
			formRow = (FormRow)this.getParent();
		}catch(Exception se){}
		try{
			if(labelwidth!=null){
				rts+="width:"+getCssValue(labelwidth);
			}else if(formRow!=null && formRow.getLabelDefaultwidth()!=null){
				rts+="width:"+getCssValue(formRow.getLabelDefaultwidth());
			}
			if(labelheight!=null){
				rts+="height:"+getCssValue(labelheight);
			}else if(formRow!=null && formRow.getLabelDefaultheight()!=null){
				rts+="height:"+getCssValue(formRow.getLabelDefaultheight());
			}
		}catch(Exception se){}
		return rts;
	}
	//--------获取默认宽/高度---------------------------------
	public String getInputDefaultwidthHeight(){
		String rts = "";
		FormRow formRow = null;//
		try{
			formRow = (FormRow)this.getParent();
		}catch(Exception se){}
		try{
			if(inputwidth!=null){
				rts+="width:"+getCssValue(inputwidth);
			}else if(formRow!=null && formRow.getInputDefaultwidth()!=null){
				rts+="width:"+getCssValue(formRow.getInputDefaultwidth());
			}
			if(inputheight!=null){
				rts+="height:"+getCssValue(inputheight);
			}else if(formRow!=null && formRow.getInputDefaultheight()!=null){
				rts+="height:"+getCssValue(formRow.getInputDefaultheight());
			}
		}catch(Exception se){}
		return rts;
	}
	//--------附加分号-------------------------------------
	public String getCssValue(String cssvalue){
		if(cssvalue!=null){
			if(!cssvalue.endsWith(";"))
				cssvalue+=";";
		}
		return cssvalue;
	}
	public String getStyle() {
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	public String getClassstyle() {
		return classstyle;
	}
	public void setClassstyle(String classstyle) {
		this.classstyle = classstyle;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public String getInputStyle() {
		return inputStyle;
	}
	public void setInputStyle(String inputStyle) {
		this.inputStyle = inputStyle;
	}
	public String getInputclassstyle() {
		return inputclassstyle;
	}
	public void setInputclassstyle(String inputclassstyle) {
		this.inputclassstyle = inputclassstyle;
	}
	public String getLabelid() {
		return labelid;
	}
	public void setLabelid(String labelid) {
		this.labelid = labelid;
	}
	public String getInputid() {
		return inputid;
	}
	public void setInputid(String inputid) {
		this.inputid = inputid;
	}
	public String getLabelwidth() {
		return labelwidth;
	}
	public void setLabelwidth(String labelwidth) {
		this.labelwidth = labelwidth;
	}
	public String getLabelheight() {
		return labelheight;
	}
	public void setLabelheight(String labelheight) {
		this.labelheight = labelheight;
	}
	public String getInputwidth() {
		return inputwidth;
	}
	public void setInputwidth(String inputwidth) {
		this.inputwidth = inputwidth;
	}
	public String getInputheight() {
		return inputheight;
	}
	public void setInputheight(String inputheight) {
		this.inputheight = inputheight;
	}
}
